﻿using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

public static class TimeSpanExtension
{
    public static string ToString(this TimeSpan timeSpan, bool hours, bool minutes, bool secends, bool millisecond, string separator = ":")
    {
        List<string> list = new List<string>();
        if (hours)
        {
            list.Add(timeSpan.Hours.ToString("D2"));
        }
        if (minutes)
        {
            list.Add(timeSpan.Minutes.ToString("D2"));
        }
        if (secends)
        {
            list.Add(timeSpan.Seconds.ToString("D2"));
        }
        if (millisecond)
        {
            list.Add(timeSpan.Milliseconds.ToString("D2"));
        }
        return string.Join(separator, list.ToArray());
    }
}

